<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>分类管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../../include/commonFile.jsp" %>
</head>
<body>
<!--头部-->
<%@include file="../../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <div class="layui-tab layui-tab-brief">
                <div class="layui-tab-content">
                    <form class="layui-form" action="${ctx}/mall/category/list.do" id="myForm" method="post">
                        <input type="hidden" name="pageNo" id="pageNo" value="${page.page}"/>
                        <div class="f-search-bar">
                            <div class="search-container">
                                <ul class="search-form-content">
                                    <li class="form-item-inline">
                                        <%-- <a href="${ctx}/mall/category/selectCategory.do?type=1"
                                            class="layui-btn layui-btn-normal copy-btn">新增一级分类</a>--%>
                                        <label class="search-form-lable">名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input"
                                                   value="${mallCategory.name}" placeholder="请输入查询类型名称">
                                        </div>
                                    </li>
                                    <li class="form-item-inline">
                                        <div class="sub-btns">
                                            <a class="layui-btn layui-btn-danger"
                                               href="javascript:submitFunction('#myForm')">查询</a>
                                            <a class="layui-btn layui-btn-normal"
                                               href="javascript:resetFunction('#myForm')">重置</a>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                        </div>

                    </form>
                    <div class="my-act-list-content">
                        <ul id="view">
                            <table class="layui-table" lay-skin="line">
                                <colgroup>
                                    <col width="150">
                                    <col width="150">
                                    <col width="150">
                                    <col width="250">
                                </colgroup>
                                <thead>
                                <tr>
                                    <th>分类名称</th>
                                    <th>商品数量</th>
                                    <th>创建时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach var="category" items="${list}">
                                    <tr>
                                        <td>${category.name}</td>
                                        <td></td>
                                        <td><fmt:formatDate value="${category.updateDate}" pattern="yyyy-MM-dd HH:mm"/></td>
                                        <td class="tb-opts">
                                            <div class="comm-opts">
                                                <a href="javascript:addFirstCategory('${category.id}')" class="green" target="_self">编辑</a>
                                                <a href="javascript:txz.deleteObject('确定要删除吗？', '${ctx}/mall/category/delete.do?id=${category.id}','该类型下已有子类型，不能删除')" class="red" target="_self">删除</a>
                                                <a href="javascript:addSecondCategory('${category.id}', '')" class="gray" target="_self">新增二级分类</a>
                                            </div>
                                        </td>
                                    </tr>
                                    <c:if test="${fn:length(category.childrens) > 0}">
                                        <c:forEach var="cCategory" items="${category.childrens}">
                                            <tr>
                                                <td style="text-indent: 20px">
                                                    <div>
                                                        <img width="35px" height="35px" src="${cCategory.pic}" style="margin-right: 5px">
                                                        <span>${cCategory.name}</span>
                                                    </div>
                                                </td>
                                                <td><a href="${ctx}/mall/goods/list.do?categoryId=${cCategory.id}" class="red" target="_blank">${cCategory.goodsNum}</a></td>
                                                <td><fmt:formatDate value="${cCategory.updateDate}" pattern="yyyy-MM-dd HH:mm"/></td>
                                                <td class="tb-opts">
                                                    <div class="comm-opts">
                                                        <a href="javascript:addSecondCategory('${cCategory.parentId}', '${cCategory.id}')" class="green" target="_self">编辑</a>
                                                        <a href="javascript:txz.deleteObject('确定要删除吗？', '${ctx}/mall/category/delete.do?id=${cCategory.id}')" class="red" target="_self">删除</a>
                                                        <a href="${ctx}/mall/category/specList.do?categoryId=${cCategory.id}" target="_self">规格列表</a>
                                                        <a href="${ctx}/mall/category/brandList.do?categoryId=${cCategory.id}" target="_self">品牌列表</a>
                                                    </div>
                                                </td>
                                            </tr>
                                        </c:forEach>
                                    </c:if>
                                </c:forEach>
                                </tbody>
                            </table>
                        </ul>
                    </div>
                    <div id="page_content" class="page-container"></div>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../../include/footer.jsp" %>
    </section>
</div>

<%@include file="../../include/incScript.jsp" %>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">
    var element = null;
    $(function () {
        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });
    })

    // 一级分类
    function addFirstCategory(categoryId) {
        function cb($jquery) {
        }

        openDialog('${empty brandId ? '新增' : '编辑'}一级分类', '${ctx}/mall/category/categoryForm.do?type=1&id=' + categoryId, '450px', '250px', cb);
    }

    // 二级分类
    function addSecondCategory(parentId, categoryId) {
        function cb($jquery) {
        }

        openDialog('${empty brandId ? '新增' : '编辑'}二级分类', '${ctx}/mall/category/categoryForm.do?type=2&parentId=' + parentId + '&id=' + categoryId, '800px', '570px', cb);
    }

    function openDialog(title, url, width, height, cb, target) {
        var index = layer.open({
            type: 2,
            area: [width, height],
            title: title,
            maxmin: true, //开启最大化最小化按钮
            content: url,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if (target) {
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                } else {
                    top_iframe = '_parent';//获取当前active的tab的iframe
                }
                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                if (iframeWin.contentWindow.doSubmit()) {
                    setTimeout(function () {
                        top.layer.close(index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug

                    setTimeout(function () {
                        window.location.reload();
                    }, 200);
                }
            },
            cancel: function (index) {
            }
        });
    }


</script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '分类管理',
            curr: true
        }],
        info: '<span class="f12">共<b id="totalCount">${page.totalCount}</b>条记录</span>',
        btns: [{
            name: '新增一级分类',
            href: 'javascript:addFirstCategory(\'\')',
            icon: 'add'
        }]
    });
</script>
</body>
</html>